﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace CoolCode.Controls
{
    public partial class Dialog : UserControl,IModalDialog 
    {
        public UserControl Panel { get; set; }
        private OnSubmit onSubmit;
        private IDialog dialog;

        public Dialog(string title, IDialog panel)
        {
            InitializeComponent();
            this.dialogPanel.Title = title;
            this.dialog = panel ;
            this.Panel = panel as UserControl ;
            this.content.Children.Add(this.Panel );
            //this.onSubmit += onSubmit;

            this.dialogPanel.Width = this.Panel.Width + 10;
            this.dialogPanel.Height = this.Panel.Height + 80;

            this.dialogPanel.OnClose += new RoutedEventHandler(this.ClosePanel);
            this.submit.Click += new RoutedEventHandler(submit_Click);
        }

        void submit_Click(object sender, RoutedEventArgs e)
        {
            this.Visibility = Visibility.Collapsed;
            this.dialog.SubmitAsync();
            if (this.onSubmit != null)
                onSubmit(this.dialog );
        }

        public void ClosePanel(object sender, RoutedEventArgs e)
        {
            this.Visibility = Visibility.Collapsed;
        }

        #region IModalDialog Members

        public void Show(Panel parent)
        {
            Window.ShowDialog(parent, this);
        }

        public void Close()
        {
            Window.CloseDialog();
        } 

        #endregion
    }
}
